package com.koron.housing.excel;

import com.alibaba.excel.converters.string.StringStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.koron.common.core.business.datadict.utils.DataDictTool;

import java.util.Map;

/**
 * @author jzp
 * @since 2022/3/11
 */
public class HousingStaffConvertor extends StringStringConverter {

    private final Map<String, String> usageType;
    private final Map<String, String> layout;
    private final Map<String, String> status;
    private final Map<String, String> propertySource;

    public HousingStaffConvertor(){
        this.usageType = DataDictTool.getDataDictByCode("housingManagement", "housing_a_usage_type");
        this.layout = DataDictTool.getDataDictByCode("housingManagement", "housing_layout");
        this.status = DataDictTool.getDataDictByCode("housingManagement", "housing_lease_status");
        this.propertySource = DataDictTool.getDataDictByCode("housingManagement", "housing_property_source");
    }

    @Override
    public WriteCellData<String> convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        String fieldName = contentProperty.getField().getName();
        if ("status".equals(fieldName)) {
            value = status.get(value);
        } else if ("layout".equals(fieldName)) {
            value = layout.get(value);
        } else if ("usageType".equals(fieldName)) {
            value = usageType.get(value);
        }
        return new WriteCellData<>(value);
    }
}
